<?php

/**
 * Created by PhpStorm.
 * User: Shroom Ari
 * Date: 11/20/14
 * Time: 11:24 AM
 */
class Mproductcategory extends MY_Model
{
    public $table = 'product_category';

    public function __construct()
    {
        parent::__construct();
    }

    function get_product_category()
    {
        $this->db->select("*");
        $query = $this->db->get("product_category");
        return $query->result_array();
    }

    function getProductCategory($perpage, $offset)
    {

        $query = $this->db->get('product_category', $perpage, $offset);
        return $query->result_array();
    }

    function getProductCategoryById($id)
    {
        $this->db->select('*');
        $this->db->from('product_category');
        $this->db->where('product_category_id', $id);
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }

    function countAll()
    {
        return $this->db->count_all('product_category');
    }

    function delete($id)
    {
        $this->db->where('product_category_id', $id);
        $this->db->delete('product_category');
        if ($this->db->_error_number() == 1451){
            return false;
        }
        return true;
    }
    function updateCategory($id, $dt)
    {
        $this->db->where('product_category_id', $id);
        if ($this->db->update('product_category', $dt))
            return TRUE;
        else return FALSE;
    }

}